package com.day1012.morning;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class MainText2 {
    public static void main(String[] args) throws Exception {
        Map<Integer,String> map = new HashMap<>();
        map.put(1,"public");
        map.put(2,"private");
        map.put(3,"protected");
        Student student = new Student();
        Class<Student> clazz = (Class<Student>) student.getClass();
        Method[] methods = clazz.getDeclaredMethods();
        for (Method method : methods) {
            System.out.print(map.get(method.getModifiers()) + " ");
            System.out.print(method.getReturnType().getName() + " ");
            System.out.print(method.getName() + "(");
            for (Class c : method.getParameterTypes()) {
                System.out.print(c.getName() + " ");
            }
            System.out.println("){ }");
        }
        //   调用
        Method setStu_name = clazz.getMethod("setStu_name",String.class);
        setStu_name.invoke(student,"张三");
        Method getStu_name = clazz.getMethod("getStu_name");
        Object object = getStu_name.invoke(student);
        System.out.println(object);

    }
}
